package org.raymond.iworks.apis.fallbackFactory;

import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.apis.ITSysPermissionServiceApi;
import org.raymond.iworks.apis.common.Result;
import org.raymond.iworks.apis.vo.permission.PermissionInfoVO;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ITSysPermissionServiceFallbackFactory implements FallbackFactory<ITSysPermissionServiceApi> {

    @Override
    public ITSysPermissionServiceApi create(Throwable throwable) {
        final String error = throwable.getMessage();
        log.error(error, throwable);
        return new ITSysPermissionServiceApi() {
            @Override
            public Result refresh() {
                return Result.error(error);
            }

            @Override
            public Result update(PermissionInfoVO vo) {
                return Result.error(error);
            }

            @Override
            public Result delete(PermissionInfoVO vo) {
                return Result.error(error);
            }

            @Override
            public Result list(PermissionInfoVO vo) {
                return Result.error(error);
            }

            @Override
            public Result getTreeByRoleId(Long id) {
                return Result.error(error);
            }

            @Override
            public Result<PermissionInfoVO> tree() {
                return Result.error(error);
            }
        };
    }
}
